package server

import (
	"gitee.com/liukexing/mqbroker/core/driver/config"
	"gitee.com/liukexing/mqbroker/core/server/http"
	"gitee.com/liukexing/mqbroker/core/server/pubsub"
	"gitee.com/liukexing/mqbroker/core/typedef"
)

const (
	ConfigName = "config.core.server"
)

var (
	RunModule []string
	submodule map[string]typedef.SubHandle
	Config    typedef.ConfigInfo
)

func init() {
	var ok bool
	Config, ok = config.GetConfig(ConfigName)
	if !ok {
		return
	}
}
func registerModel() {
	submodule = make(map[string]typedef.SubHandle)
	submodule["pubsub"] = pubsub.Run
	submodule["http"] = http.Run
}
func initSubModule(module string) bool {
	if Run, ok := submodule[module]; ok {
		return Run()
	}
	return true
}

func Start() bool {
	if !Config.Info.Enable {
		return true
	}
	registerModel()
	for _, v := range Config.Info.SubModule {
		if !initSubModule(v) {
			RunModule = append(RunModule, v)
		}
	}
	return false
}
